package com.dys.testqueue16;

import java.util.concurrent.PriorityBlockingQueue;

/**
 * @className: com.dys.testqueue16.PriorityBlockingQueueTest
 * @description: com.dys.testqueue16
 * @author: pine cone
 * @version: v1.0.0
 * @createTime: 2024/08/12 下午11:07
 */
public class PriorityBlockingQueueTest {

    /**
     * 这是一个main()方法,是应用程序的入口
     *
     * @param args 方法的形参列表,是一个字符串数组,包含了从命令行传递给程序的参数
     */
    public static void main(String[] args) throws InterruptedException {
        new PriorityBlockingQueueTest().testPriorityBlockingQueue2();
    }

    public void testPriorityBlockingQueue() {
        PriorityBlockingQueue<String> pq = new PriorityBlockingQueue<String>();
        // 不允许放入null元素
        pq.add(null);
        pq.add("b");
    }

    /**
     * 优先级队列：只针对于取数据时
     *
     * @throws InterruptedException
     */
    public void testPriorityBlockingQueue2() throws InterruptedException {
        PriorityBlockingQueue<Student> pq = new PriorityBlockingQueue<>();
        // 不允许放入null元素
        pq.put(new Student("Bob", 10));
        pq.put(new Student("Alice", 20));
        pq.put(new Student("Roy", 15));
        pq.put(new Student("Lili", 30));
        pq.put(new Student("Tom", 40));
        System.out.println(pq);
        System.out.println(pq.size());
        System.out.println("=======================");
        System.out.println(pq.take());
        System.out.println(pq.take());
        System.out.println(pq.take());
        System.out.println(pq.take());
        System.out.println(pq.take());
    }
}
